/*
* Authoer:JacksonCoder
* CreateTime:
* Version: 1.0.0
*/

enum TrafficLight {
    Red,
    Yellow,
    Green,
    Unknown, // Unknown变体
}

fn main() {
    homework1();
    homework2();
    homework3();

}

fn homework3(){
    let n = Some(3);

    fn square_option(opt: Option<i32>) -> i32 {
        match opt {
            Some(x) => x * x,
            None => 0,
        }
    }

    println!("n 为{}", square_option(n));
}

fn homework2() {
    let light = TrafficLight::Green;

    match light {
        TrafficLight::Red => println!("停"),
        TrafficLight::Green => println!("走"),
        TrafficLight::Yellow => println!("等待"),
        TrafficLight::Unknown => println!("未知"),
    };
}

fn homework1() {
    for i in 1..101 {
        println!("value: {}", i);
        let n = Some(i);
        match n {
            Some(x) if x % 3 == 0 && x % 5 == 0 => println!("FizzBuzz"),
            Some(x) if x % 3 == 0 => println!("Fizz"),
            Some(x) if x % 5 == 0 => println!("Buzz"),
            Some(x) => println!("数字:{}", x),
            _ => println!("未知"),
        }
    }
}
